package edu.cibertec.sicsolutions.vfs.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;

import edu.cibertec.sicsolutions.constants.Constants;
import edu.cibertec.sicsolutions.constants.SessionConstants;
import edu.cibertec.sicsolutions.util.StringUtil;
import edu.cibertec.sicsolutions.vfs.domain.votacion.Cedula;
import edu.cibertec.sicsolutions.vfs.service.CedulaService;

public class CedulaAction extends DispatchAction{
	
	public ActionForward init(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {		
           
        Cedula[]  listAniosCedula =CedulaService.findAniosCedula();
        Cedula[] listCedulas = null;
        
        if(!StringUtil.isNullOrEmpty(request.getParameter("anioCedula")) ){
        	Cedula cedula = new Cedula();
        	cedula.setAnio(request.getParameter("anioCedula"));
        	listCedulas = CedulaService.findCedulasByAnio(cedula);
        }
        else{
        	listCedulas = CedulaService.findAllCedulas();
        }
		 
		HttpSession session = request.getSession();
		session.setAttribute(SessionConstants.LIST_ANIOS_CEDULA, listAniosCedula);
		session.setAttribute(SessionConstants.LIST_CEDULA, listCedulas);
		return mapping.findForward(Constants.SUCCESS_INIT);
	}
	
	public ActionForward add(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		    
 		 
		return mapping.findForward("addCedula");
	}
	
}
